#!/usr/bin/env bash
proxy_ip="192.168.100.225"
proxy_port="8889"
proxy="http://${proxy_ip}:${proxy_port}"
host="pypi.douban.com"
param_i="http://${host}/simple"

function usage() {
    echo "Usage: $( basename $0 ) [-n | -h] <pkgs1> [<pkgs2>...]"
    echo "    -n: dry run"
    echo "    -h: 输出此信息"
    exit 1
}

dryRun=false
shiftCnt=0
while getopts "nh" args
do
    case "${args}" in
        n)
            dryRun=true
            shiftCnt=$(( ${shiftCnt} + 1 ))
            ;;
        *)
            usage
            shiftCnt=$(( ${shiftCnt} + 1 ))
            ;;
    esac
done

shift ${shiftCnt}

if [ $# -eq 0 ]
then
    usage
    echo "没有指定任何安装包"
fi

echo pip install \\
echo "   $@ \\"
echo "   --proxy=${proxy} \\"
echo "   -i ${param_i} \\"
echo "   --trusted-host ${host}"

if ${dryRun}
then
    exit 0
fi

pip install \
    "$@" \
    --proxy="${proxy}" \
    -i ${param_i} \
    --trusted-host ${host} 
